# -*- coding: utf-8 -*-
# @Time    : 2021/4/5 18:07
# @Author  : xxue
# @Email   : x_xue1212@163.com
# @File    : 三乐购物系统.py
# @Software: PyCharm


# 登录验证
for i in range(3):
    username = input("请输入用户名：")
    password = input("请输入密码：")
    if username == "root" and password == "123456":
        print("登录成功")
        break
    elif i >= 2:
        print("登陆失败")
    else:
        print(f"还有{2 - i}次尝试机会")

# 输入购物预算
budget = int(input("请输入您的购物预算:"))

# 采集商品信息
goods_dict1 = {'苹果': {'number': 'F00001', 'price': 1.2}}
goods_dict2 = {'香蕉': {'number': 'F00002', 'price': 5.5}}
goods_dict3 = {'梨子': {'number': 'F00003', 'price': 5.5}}
goods_dict = dict(goods_dict1, **goods_dict2, **goods_dict3)

shopping_goods_cart = {}

# 查找商品信息
while True:
    str = input("请输入您要查看的商品信息:")

    if str == 'exit':
        break

    if str in goods_dict.keys():
        print(f"{str}的编号是{goods_dict[str]['number']},价格是{goods_dict[str]['price']}")
        admin_count = int(input("请输入购买数量："))

        if admin_count == "eixt":
            break
    else:
        print("此商品不存在")

    # 添加购物车
    if str not in shopping_goods_cart.keys():

        mid = {str:
                   {'number': goods_dict[str]['number'],
                    'price': goods_dict[str]['price'],
                    'count': admin_count}
               }
        shopping_goods_cart.update(mid)

    else:
        count = shopping_goods_cart[str]['count'] + admin_count
        shopping_goods_cart[str]['count'] = count
print(shopping_goods_cart)

# 付款
price_all = 0
for key in shopping_goods_cart.keys():
    price_all += shopping_goods_cart[key]['price'] * shopping_goods_cart[key]['count']
if budget < price_all:
    print("预算不够")
else:
    budget -= price_all
    print(f"{budget:.2f}")
